package product;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;

import java.awt.event.KeyAdapter;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.net.URL;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.JFrame;

public class ProductMain1 extends JInternalFrame {

	private JDesktopPane contentPane;
	private JMenuBar menuBar;
	private JMenu mnNewMenu;
	private JMenuItem mntmNewMenuItem;
	
	Login login = null;
	
	boolean flag1 = false; // 코드 데이터가 수정되었을 경우를 판별할 수 있는 변수 
	boolean flag2 = false; // 프로덕트 데이터가 수정되었을 경우를 판별할 수 있는 변수 

	
	public ProductMain1() {
		super("1조-급여관리", true, true, true, false);
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameClosing(InternalFrameEvent e) {
				try {
					if(login != null){
						if(login.conn != null) login.conn.close();
					}
				} catch (Exception e2) {
					e2.printStackTrace();
				}
			}
			@Override
			public void internalFrameDeactivated(InternalFrameEvent e) {
				contentPane.removeAll();
				login = null;
			}
		});
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		
		URL url = getClass().getClassLoader().getResource("icon.png");
		Image img = Toolkit.getDefaultToolkit().getImage(url);
		this.setFrameIcon(new ImageIcon(img));
		
		try {
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			SwingUtilities.updateComponentTreeUI(this);
	        UIManager.put("InternalFrame.titleFont", new Font("Gulim", Font.PLAIN, 11));
	        
		} catch (ClassNotFoundException | InstantiationException
				| IllegalAccessException | UnsupportedLookAndFeelException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		setBounds(100, 100, 600, 450);
		setJMenuBar(getMenuBar_1());
		contentPane = new JDesktopPane();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
	}

	private JMenuBar getMenuBar_1() {
		if (menuBar == null) {
			menuBar = new JMenuBar();
			menuBar.add(getMnNewMenu());
		}
		return menuBar;
	}
	private JMenu getMnNewMenu() {
		if (mnNewMenu == null) {
			mnNewMenu = new JMenu("메뉴");
			mnNewMenu.setFont(new Font("맑은 고딕", Font.PLAIN, 11));
			mnNewMenu.add(getMntmNewMenuItem());
		}
		return mnNewMenu;
	}
	private JMenuItem getMntmNewMenuItem() {
		if (mntmNewMenuItem == null) {
			mntmNewMenuItem = new JMenuItem("급여메인");
			mntmNewMenuItem.setFont(new Font("맑은 고딕", Font.PLAIN, 11));
			mntmNewMenuItem.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					
					if (login == null) { 
						login = new Login();
						login.getMain(ProductMain1.this);
						login.setBounds(0, 0, 488, 375);
						contentPane.add(login);
					}
			
					login.setVisible(true);
				
				}
			});
			mntmNewMenuItem.addKeyListener(new KeyAdapter() {
				
			});
		}
		return mntmNewMenuItem;
	}
}
